package com.huike.web.controller.report;

import com.huike.business.service.ITbBusinessService;
import com.huike.clues.domain.TbClue;
import com.huike.clues.service.ITbClueService;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.contract.domain.TbContract;
import com.huike.contract.service.ITbContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/report")
public class ReportController extends BaseController {

    @Autowired
    private ITbClueService tbClueService;
    @Autowired
    private ITbBusinessService tbBusinessService;
    //@Autowired
    //private ITbBusinessService iTbBusinessService;
    @Autowired
    private ITbContractService tbContractService;


    // @PreAuthorize("@ss.hasAnyPermi('report:getVulnerabilityMap:time')")
    @GetMapping("/getVulnerabilityMap/{beginCreateTime}/{endCreateTime}")
    public AjaxResult getVulnerabilityMap(@PathVariable String beginCreateTime, @PathVariable String endCreateTime) {
        TbClue tbClue = new TbClue();
        Map<String, Object> params = tbClue.getParams();
        params.put("beginCreateTime", beginCreateTime);
        params.put("endCreateTime", endCreateTime);

//        TbBusiness tbBusiness = new TbBusiness();
//        Map<String, Object> params1 = tbBusiness.getParams();
//        params1.put("beginCreateTime", beginCreateTime);
//        params1.put("endCreateTime", endCreateTime);

        TbContract tbContract = new TbContract();
        Map<String, Object> params2 = tbContract.getParams();
        params2.put("beginCreateTime", beginCreateTime);
        params2.put("endCreateTime", endCreateTime);

        List<TbClue> tbClues = tbClueService.selectTbClueList(tbClue);
        //获取无效线索数
        int count = 0;

        for (int i = 0; i < tbClues.size(); i++) {
            String status = tbClues.get(i).getStatus();
            if ("4".equals(status)) {
            }
            count = count + 1;
        }
        // String beginCreateTime, String endCreateTime
        int businessNums = tbBusinessService.selectTbBusinessListByTime(beginCreateTime, endCreateTime);


        List<TbContract> contractList = tbContractService.selectTbContract(tbContract);
        int cluesNums = tbClues.size();


        int contractNums = contractList.size();
        int effectiveCluesNums = cluesNums - count;
        HashMap<String, Integer> map = new HashMap<>();
        map.put("cluesNums", cluesNums);
        map.put("effectiveCluesNums", effectiveCluesNums);
        map.put("businessNums", businessNums);
        map.put("contractNums", contractNums);
        System.out.println(map);
        return AjaxResult.success(map);
    }
}